#include<iostream>
using namespace std;
const int N = 110;
int n;
int arr[N];
int main()
{
	cin >> n;
	for (int i = 1; i <= n; i++) {
		int x;
		cin >> x;
		arr[x]++;
	}
	int ans = 0;
	for (int i = 1; i < n; i++) {
		for (int j = i + 1; j <= n; j++) {
			ans += (arr[j] * arr[i]) * (j - i);
		}
	}
	cout << ans << endl;
	return 0;
}